#!/bin/bash

set -e
set -v

echo "********* test http trigger ************"
cd ./http
export fc_component_function_name=test-http-trigger-$(uname)-$(uname -m)-$RANDSTR
echo "test nodejs14 runtime http trigger ..."

s deploy --function -y
s deploy --trigger http_t -y
s version publish --description test
s alias publish --alias-name test --version-id latest
s alias get --alias-name test
s alias list

s deploy --trigger http_t2

s info
s plan
s invoke -e 'hello latest'
s invoke -e 'hello latest' --qualifier 'test'

s remove -y

if [ -n "$region" ] && [ "$region" != "cn-huhehaote" ]; then
  echo "Region is not equal to cn-huhehaote. skip eb and other trigger test"
  exit 0
fi

echo "********* test other trigger ************"
cd ../other
export fc_component_function_name=test-other-trigger-$(uname)-$(uname -m)-$RANDSTR
echo "test nodejs14 runtime with timer/oss/sls/mns trigger ..."
s deploy  -y
s info
s plan
s remove -y

echo "********* test event bridge trigger ************"
cd ../eb
export fc_component_function_name=test-eb-trigger-$(uname)-$(uname -m)-$RANDSTR
echo "test nodejs14 runtime with eb trigger ..."
s deploy  -y
s info
s plan
s remove -y
cd ..